<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:OutputProcessFilter.php,2010/05/18 16:32:17 
 * 
 **************************************************************************/
 
 
 
/**
 * @file OutputProcessFilter.php
 * @author huqingping
 * @date 2010/05/18 16:32:17
 * @version 1.0 
 * @brief 
 *  
 **/

class OutputProcessFilter implements IFilter
{
	function execute(WebApp $app)
	{
		$to = $app->request->oe;
		if ($app->encoding !== $to) {
			require_once FR_ROOT.'core/Encoding.php';
			$app->response->outputs = $this->_transEncoding($app->response->outputs,$to,$app->encoding);
			$app->response->headers = $this->_transEncoding($app->response->headers,$to,$app->encoding);
		}
		$app->response->send();
	}

	private function _transEncoding($arr, $to, $from)
	{
		$ret = array();
		foreach($arr as $key=>$value) {
			if (is_array($value)) {
				$value = $this->_transEncoding($value,$to,$from);
			} else {
				$value = Encoding::convert($value,$to, $from);
			}
			if (is_string($key)) {
				$key = Encoding::convert($key,$to, $from);
			}
			$ret[$key] = $value;
		}
		return $ret;
	}

}





/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */